package models

import (
	// "gorm.io/driver/mysql"
	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
)

var DB *gorm.DB

func NewGormDB() {
	//dsn := "root:root@tcp(127.0.0.1:3306)/go-admin?charset=utf8mb4&parseTime=True&loc=Local"
	// dsn := "root:Fly099232@tcp(gz-cynosdbmysql-grp-0w3te4et.sql.tencentcdb.com:29204)/go-admin?charset=utf8mb4&parseTime=True&loc=Local"
	// db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
	// 	DisableForeignKeyConstraintWhenMigrating: true,
	// })
	db, err := gorm.Open(sqlite.Open("admin-ip.db"), &gorm.Config{
		DisableForeignKeyConstraintWhenMigrating: true,
	})

	if err != nil {
		panic(err)
	}

	// 自动建表
	db.AutoMigrate(&SysUser{}, &SysRole{}, &SysMenu{}, &RoleMenu{}, &SysLog{}, &IPInternetPublic{})

	DB = db

}
